<script setup lang="ts">
import { watch, unref, toRef } from "vue";
import useImgScaleTap from "./useImgScaleTap";

let props = defineProps(["src"]);
let emit = defineEmits(["close"]);

let src = toRef(props, "src");

let {
  isFullScreen,
  touchstart,
  touchend,
  handleCurrentChange,
  current,
  toFullScreen,
} = useImgScaleTap();
let stopPro = (evt: Event) => {
  evt.stopPropagation();
  evt.preventDefault();
};

watch(src, () => {
  if (unref(src)) {
    toFullScreen();
  }
});
watch(isFullScreen, () => {
  if (!unref(isFullScreen)) {
    emit("close");
  }
});
</script>

<template>
  <div
    v-if="isFullScreen"
    class="full-screen-wrap"
    @touchstart.stop.prevent="touchstart"
    @touchend.stop.prevent="touchend"
    @dblclick.stop.prevent="stopPro"
  >
    <view class="swiper-item">
      <movable-area class="movable-area">
        <movable-view
          class="movable-view"
          direction="all"
          :scale-value="1"
          :scale="true"
          :scale-min="1"
          :scale-max="4"
        >
          <image class="img-item" :src="src" mode="widthFix" lazy-load />
        </movable-view>
      </movable-area>
    </view>
  </div>
</template>

<style lang="less" scoped>
.full-screen-wrap {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 1);
  z-index: 5;
}

.img-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.swiper-item {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);

  .movable-area {
    width: 100%;
    height: 100%;
    .movable-view {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}

.img-item {
  width: 100%;
}
</style>
